<?php

namespace app\api\controller;

use app\api\model\TrainModel;
use think\Controller;

class Train extends Controller {
    function trainlist() {
        $model = new  TrainModel();
        $result = $model->trainlist();
        return json($result);
    }

    function traindetail() {
        $traindetail = input('get.trainid');
        $model = new  TrainModel();
        $result = $model->traindetail($traindetail);
        if ($result) {
            return json($result);
        }
    }

    function posttrain() {
        $userid = input('get.userid');
        $trainid = input('get.trainid');

        $model = new  TrainModel();
        $result = $model->posttrain($userid, $trainid);
        if ($result == 1) {
            return json("你已经报过此培训了");
        } else if ($result == 2) {
            return json(['success' => 1]);
        } else if ($result == 3) {
            return json("报名失败");
        }
    }

}